﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataTighteningData" @search="getTableDataTighteningData">
      <el-row>
        
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="TID_FormItem" prop="TID" label="TID">
            <el-input-number v-model="searchDataTighteningData.TID" clearable></el-input-number>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="toolSerialNum_FormItem" prop="toolSerialNum" label="toolSerialNum">
            <el-input v-model="searchDataTighteningData.toolSerialNum" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="tighteningID_FormItem" prop="tighteningID" label="tighteningID">
            <el-input-number v-model="searchDataTighteningData.tighteningID" clearable></el-input-number>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="tool_id_FormItem" prop="tool_id" label="tool_id">
            <el-input-number v-model="searchDataTighteningData.tool_id" clearable></el-input-number>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="sn_FormItem" prop="sn" label="sn">
            <el-input v-model="searchDataTighteningData.sn" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="project_name_FormItem" prop="project_name" label="project_name">
            <el-input v-model="searchDataTighteningData.project_name" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="torque_FormItem" prop="torque" label="torque">
            <el-input v-model="searchDataTighteningData.torque" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="upload_status_FormItem" prop="upload_status" label="upload_status">
            <el-input v-model="searchDataTighteningData.upload_status" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="upload_time_FormItem" prop="upload_time" label="upload_time">
            <el-input v-model="searchDataTighteningData.upload_time" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="filed1_FormItem" prop="filed1" label="filed1">
            <el-input v-model="searchDataTighteningData.filed1" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="filed2_FormItem" prop="filed2" label="filed2">
            <el-input v-model="searchDataTighteningData.filed2" clearable></el-input>
        </el-form-item>
    </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
      <WtmButton v-auth="'/api/TighteningData/Add'" icon='fa fa-plus' type='primary' :button-text="$t('message._system.common.vm.add')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/TighteningData/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message._system.common.vm.batchdelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/TighteningData/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message._system.common.vm.import')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/TighteningData/ExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message._system.common.vm.export')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefTighteningData" v-bind="tableDataTighteningData">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
        <el-button  text type="primary" @click="showGrph(scope.row)">查看曲线图</el-button>
          <el-button text type="primary" @click="OnEditrowClick(scope.row)" v-auth="'/api/TighteningData/Edit'">{{ $t('message._system.common.vm.edit') }}</el-button>
					<el-button text type="primary" @click="OnDetailsrowClick(scope.row)" v-auth="'/api/TighteningData/{id}'">{{ $t('message._system.common.vm.detail') }}</el-button>
					<el-popconfirm :title="$t('message._system.common.vm.deletetip')"  @confirm="onDelete(scope.row)">
						<template #reference>
							<el-button text type="danger" v-auth="'/api/TighteningData/BatchDelete'">{{ $t('message._system.common.vm.delete') }}</el-button>
						</template>
					</el-popconfirm>
        </template>
      </el-table-column>
    </template>
    
  </WtmTable>
  <el-dialog v-model="showModal" title="拧紧曲线" style="text-align: center;width:1200px;height: 600px;" >
    <div ref="controlChart1" style="width: 1100px;height: 500px;"></div>
  </el-dialog>

</el-card>
</div>
</template>


<script setup lang="ts" name="拧紧数据;true;TyMES.Controllers;TighteningData">
import {  ElMessageBox, ElMessage } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { TighteningDataApi } from '/@/api/record/TighteningData';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;
import * as echarts  from 'echarts';

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const showModal = ref(false);
const graphArry = ref([]);
const chart1 = ref(null);
const controlChart1 = ref(null);
const initgrap = ref(0);

const showGrph = (row: any) =>{
    if(initgrap.value!=0)
        ClearLineData();
    initgrap.value+=1,
    graphArry.value = row.ArrTorque.split(","),
    showModal.value = !showModal.value;
    tighteningGraph(chart1,controlChart1);
    //console.log('qx',showModal.value);
}

const ClearLineData = ()=> {
    graphArry.value=[];
    if (chart1.value != null && chart1.value.dispose) { 
    console.log('卸载曲线图1') 
    chart1.value.dispose();  
    chart1.value = null;  
    }}

const tighteningGraph = async (myChart: any,chartRef:any) => {
    try {
     myChart.value = echarts.init(chartRef.value);
      const option = {
        title: {
          text: '拧紧曲线',
          x: 'center',
          textStyle: {
            fontSize: 18,
            fontWeight: 'bold',
            color: '#ffffff',
          },
          
        },
        tooltip: {
          trigger: 'axis',
          axisPointer:{
            type:"cross"
          }
        },
        xAxis: {
          type: 'category',
          name: '角度',
          data: Array.from({length:graphArry.value.length},(_,i)=>i),  // 假设数据中有 weeks 字段表示周次
          axisLabel: {
          color: '#ffffff',  // 设置图例字体为白色
        },
        },
        yAxis: {
          type: 'value',
          name: '扭矩',
          axisLabel: {
            show:true,
            rotate:0,
            formatter:'{value}',
            color: '#ffffff',  // 设置图例字体为白色
        },
        axisTick:{
            show:true,
        },
        axisLine:{
            show:true,
        },
        },
        // dataZoom:[
        //     {
        //         type:'slider',
        //         show:true,
        //         start:0,
        //         end:10
        //     },
        //     {
        //         type:'inside',
        //         start:0,
        //         end:10
        //     }
        // ],
        series: [
          {
            name: '拧紧值',
            type: 'line',
            large:true,
            sampling:'average',
            lageThreshold:10000,
            data: graphArry.value.map(Number),  // 计划产量数据
            smooth:true,
            itemStyle:{
                color:'#FF9800'
            }
          },
        ],
      };
      myChart.value.setOption(option);
    } catch (error) {
      console.error('获取拧紧曲线数据失败:', error);
    }
  };

const stateTighteningData = reactive({
    
});

const searchDataTighteningData = ref({
    			TID: null,
			toolSerialNum: null,
			tighteningID: null,
			tool_id: null,
			sn: null,
			project_name: null,
			torque: null,
			upload_status: null,
			upload_time: null,
			filed1: null,
			filed2: null,

});

// 定义变量内容
const tableRefTighteningData = ref();
const tableDataTighteningData = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
  
        {title:'TID',key: 'TID',type: 'text',isCheck: true},
        {title:'toolSerialNum',key: 'toolSerialNum',type: 'text',isCheck: true},
        {title:'tighteningID',key: 'tighteningID',type: 'text',isCheck: true},
        {title:'tool_id',key: 'tool_id',type: 'text',isCheck: true},
        {title:'sn',key: 'sn',type: 'text',isCheck: true},
        {title:'project_name',key: 'project_name',type: 'text',isCheck: true},
        {title:'torque',key: 'torque',type: 'text',isCheck: true},
        {title:'angle',key: 'angle',type: 'text',isCheck: true},
        {title:'tightening_status',key: 'tightening_status',type: 'text',isCheck: true},
        {title:'rawdata_time',key: 'rawdata_time',type: 'text',isCheck: true},
        {title:'screw_id',key: 'screw_id',type: 'text',isCheck: true},
        {title:'PointNum',key: 'PointNum',type: 'text',isCheck: true},
        {title:'angle_offset',key: 'angle_offset',type: 'text',isCheck: true},
        {title:'ArrTorque',key: 'ArrTorque',type: 'text',isCheck: true},
        {title:'upload_status',key: 'upload_status',type: 'text',isCheck: true},
        {title:'upload_time',key: 'upload_time',type: 'text',isCheck: true},
        {title:'filed1',key: 'filed1',type: 'text',isCheck: true},
        {title:'filed2',key: 'filed2',type: 'text',isCheck: true},
	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataTighteningData = () => {
    tableRefTighteningData.value.doSearch(TighteningDataApi().search, searchDataTighteningData.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.add'), CreateDialog, null, getTableDataTighteningData)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.edit'), EditDialog, row, getTableDataTighteningData)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.detail'), DetailsDialog, row, getTableDataTighteningData)
};

// 删除
const onDelete = (row: any) => {
    TighteningDataApi().delete([row.ID]).then(() => { getTableDataTighteningData()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefTighteningData.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      TighteningDataApi().delete(selectedids).then(() => { getTableDataTighteningData()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.import'), ImportDialog, null, getTableDataTighteningData)
};

const onExport = () => {
  getTableDataTighteningData();
	const selected = tableDataTighteningData.value.data;
  //console.log('ww',tableDataTighteningData.value.data);
	if (selected.length > 0) {
		TighteningDataApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		TighteningDataApi().export(searchDataTighteningData.value);
	}
};

// 页面加载时
onMounted(() => {
     
      getTableDataTighteningData();
});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">
.chart2 {
  /* 如果你希望图表有一些默认的样式，可以加上下面的设置 */
  border: 1px solid #ddd; 
  //border-radius: 8px;
  height: 100%;
  //padding: 2%;
  width: 100%;
  //margin-left: 1%;
  display: flex;
}
</style>

